import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class Lambda {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> result = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            return 2 * 3;
        }).thenCompose(i -> {
            System.out.println("thenCompose: " + Thread.currentThread().getName());
            return CompletableFuture.supplyAsync(() -> {
                System.out.println("supplyAsync2: " + Thread.currentThread().getName());
                return i * 3;
            });
        }).thenApply(i -> {
            System.out.println("last: " + Thread.currentThread().getName());
            return i + 3;
        });
        System.out.println(result.get());
    }
}
